<?php

#doc
#	classname:	UserController
#	scope:		PUBLIC
#
#/doc

class UserController extends Controller
{
	#	internal variables
	var $users;
	#	Constructor
	function __construct (  )
	{
		$this->useModel('user');
		Classloader::getInstance()->loadPlugin("Menu");
		Menu::getInstance()->addMenuEntry("Add", Utility::buildUrl("User", "create"));
		Menu::getInstance()->addMenuEntry("List", Utility::buildUrl("User", "listAll"));
	}
	###

	function show ( )
	{
		$id = $_GET['id'];
		$this->user->find($id);
	}

	function listAll ( )
	{
		$this->users = $this->user->findAll();
	}

	function create ( )
	{
		if(isset($_POST['name'])){
			$this->user->name = $_POST['name'];
			$this->user->password = md5($_POST['password']);
			$this->user->save();
			RoutingEngine::getInstance()->redirectToAction('User','show',$this->User->id);
			$this->flash('New User created');
		}
	}

	function delete ( )
	{
		$this->user->find($_GET['id']);
		$this->user->delete();
		RoutingEngine::getInstance()->redirectToAction('User','listAll');
	}

	public function edit ( )
	{
		$this->user->find($_GET['id']);
		if($_POST['action']=='update'){
			$this->user->name = $_POST['name'];
			$this->user->save();
			RoutingEngine::getInstance()->redirectToAction('User','show',$this->User->id);
		}
	}

	public function logon ( )
	{
		$email = $_POST['user'];
		$password = $_POST['password'];
		if(isset($email)&&isset($password))
		{
			Login::getInstance()->logon($email, $password);
		}
	}

	public function logoff()
	{
		Login::getInstance()->logoff();
	}
}
###

?>